<html>
<style type="text/css">
body {
	font-family:verdana,arial,sans-serif;
	font-size:10pt;
	margin:30px;
	background-color:#ffcc00;
	}
</style>

<a href = "normalorderbook.php" target = "_top"> Order another book </a><br>

</html>

<?php
date_default_timezone_set('UTC');

$username="bsc353_4";
$password="sonbeans";
$database="bsc353_4";


$ordernumber; //= intval($_POST['ordernumberprice']);


$ISBN=$_POST['ISBN'];
$quantity= intval($_POST['quantity']);
$branch=$_POST['branch'];
//$publisher=$_POST['publisher'];
$date=date("Y-m-d H:i:s"); 




if($ISBN==""||$quantity==""||$branch=="Select One")
{
    echo "Error. Please enter both the Customer ID and Branch ID";
}
else
{

    mysql_connect("clipper.encs.concordia.ca",$username,$password) or die ("Unable to connect to database");

    @mysql_select_db($database) or die ("Unable to select database");

    $orderquery= "Select max(orderNumber) from Orders";

    $ordernumber= mysql_query($orderquery) or die ("Could not increase value");
    //echo "order number: $ordernumber"; 
    $maxvalue=intval(mysql_result($ordernumber,0,"max(orderNumber)"))+1;

    //echo "$maxvalue";
    // Check connection
    $queryPublisher = "SELECT Publisher FROM Book WHERE ISBN = '$ISBN';";
    $queryPublisherResult = mysql_query($queryPublisher);
    $j = 0;
    $publisher = mysql_result($queryPublisherResult, $j, "publisher"); 
    //echo "publisher = $publisher";

    $query="INSERT INTO Orders VALUES ($maxvalue,'$date', '$ISBN', $quantity, '$branch', '$publisher','','','Requested')";

    //echo "query: $query \n"; 
    mysql_query($query) or die ("failed to add record");



    //VALUES
    //('$_POST[price]','$_POST[year]','$_POST[ISBN]', '$_POST[author]', '$_POST[subject]', '$_POST[publisher]', '$_POST[title]',
    //'$_POST[quantity]')";

    echo "Place order succeeded";


    mysql_close();
}
?> 

